const groupResOptmain = eval("require")(`../../../../../plugins/res_genrator/out/resgenrator`).groupResOptmain;

export class resGroupUntil {

	constructor() {
	}

	private static _instance;
	public static get Instance(): resGroupUntil {
		if (this._instance == null) {
			this._instance = new resGroupUntil();
		}
		return this._instance;
	}

	//新项目资源管理
	public async getResGroupArr(): Promise<any[]> {
		// await new res_genrator.ResGenrator(this.rootPath).getGroupCfgByName(this.fileName)
		let arr = [];
		try {
			arr = await groupResOptmain({ act: "getGroupCfg", path: this.resPath, extra: [] })
		} catch (error) {
			return Promise.reject(error);
		}
		return Promise.resolve(arr);
	}

	public async saveresGroup(resFileString: string): Promise<any> {
		//1.group保存 cfg.json保存
		// let configJsonObj: tools.GENRATOR_CFG_TYPE =
		// await new cfg_genrator.CfgGenRator(arr[0]).ConfigGenrator()
		//2.default.res.json更新
		// await new res_genrator.ResGenrator(this.rootPath).CfgLoader(configJsonObj, false);
		try {
			await groupResOptmain({ act: "save", path: this.resPath, extra: resFileString });
			return Promise.resolve({ mtime: new Date().getTime() })
		} catch (error) {
			return Promise.reject(error);
		}
	}

	public set ResPath(path: string) {
		this.resPath = path;
	}

	public get IsNewRes(): boolean {
		return this.isNewRes;
	}

	public setIsNewRes() {
		this.isNewRes = !this.isNewRes;
	}

	private resPath: string = "";// 项目根目录/default.res.json之类
	private isNewRes: boolean = false;//是否是 新项目 group地址

}